package com.kingint.web.admin.serve.controller;


import com.kingint.mbg.dto.BackQueryParam;
import com.kingint.mbg.group.Insert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kingint.common.unitedresult.K;

import com.kingint.web.admin.serve.service.SerSendMessageService;
import com.kingint.mbg.ser.entity.SerSendMessage;

import javax.annotation.Resource;


/**
 * @描述：群发通知表控制类
 * @作者: wxh
 * @日期: 2020-12-25
 */
@RestController
@RequestMapping("/serSendMessage")
@Api(value = "SerSendMessageController", description = "群发通知表")
@CrossOrigin
public class SerSendMessageController {

    @Resource
    public SerSendMessageService serSendMessageService;

    @ApiOperation(value = "添加群发通知表")
    @PostMapping("/create")
//    @PreAuthorize("hasAuthority('serSendMessage:create')")
    public Object create(@Validated(Insert.class) @RequestBody SerSendMessage serSendMessage) {
        int i = serSendMessageService.insertSendMessageInfo(serSendMessage);
        if (i > 0) {
            return K.ok().data(serSendMessage.getId());
        } else {
            return K.error();
        }
    }

    @ApiOperation(value = "删除群发通知表")
    @DeleteMapping("/delete/{id}")
//    @PreAuthorize("hasAuthority('serSendMessage:delete')")
    public Object delete(@PathVariable("id") Integer id) {
        Integer integer = serSendMessageService.deleteSendMessage(id);
        if (integer > 0) {
            return K.ok();
        } else {
            return K.error();
        }
    }

    @ApiOperation(value = "根据群发通知表名称分页获取群发通知表列表")
    @GetMapping("/list")
//    @PreAuthorize("hasAuthority('serSendMessage:list')")
    public Object getList(BackQueryParam queryParam,
                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        IPage<SerSendMessage> sendMessageList = serSendMessageService.getSendMessageList(queryParam, pageNum, pageSize);
        return K.ok().data(sendMessageList);
    }

    @ApiOperation(value = "根据编号查询群发通知表信息")
    @GetMapping("/{id}")
//    @PreAuthorize("hasAuthority('serSendMessage:get')")
    public Object getItem(@PathVariable("id") Integer id) {
        SerSendMessage serSendMessage = serSendMessageService.getById(id);
        return K.ok().data(serSendMessage);
    }


    @ApiOperation(value = "修改群发通知信息")
    @PostMapping("/update")
    public Object updateInfo(@RequestBody SerSendMessage serSendMessage) {
        Integer integer = serSendMessageService.updateInfo(serSendMessage);
        if (integer > 0) {
            return K.ok();
        } else {
            return K.error();
        }
    }
}